<?php

namespace App\Http;

Trait FormatReturn 
{
    public function success($data = [])
    {
        return response()->json([            
            'status'  => true,            
            'code'    => 200,            
            'message' => config('errorcode.code')[200],            
            'data'    => $data,
        ])->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    } 

    public function fail($code, $data = [])
    {
        $errorCodeArray = config('errorcode.code');
        if( array_key_exists($code,$errorCodeArray) ){
            $message = $errorCodeArray[(int) $code];
        }else{
            $message = $errorCodeArray[910000];
        }
        return response()->json([            
            'status'  => false,            
            'code'    => $code,            
            'message' => $message,            
            'data'    => $data,
        ])->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }

}